<?php

/**
 * @author  Samuel Carlier
 * @package P3Base_Language
 */
class P3Base_Language_Translator {

	/**
	 * @var string
	 */
	private static $_language_name;

	/**
	 * @var string
	 */
	private static $_language;

	/**
	 * @param string $lang language name
	 */
	public static function setLang($language) {
		$file = P3BASE . 'Language/Translations/' . $language . '.php';

		if(!file_exists($file)) {
			throw new P3Base_Language_Exception('unsupported language "'.$language.'"');
		}

		require $file;

		self::$_language = $lang;
		self::$_language_name = $language;
	}

	/**
	 * Retrieve the content of given index 
	 * in choosen language
	 *
	 * @param  string $index
	 * @return string
	 */
	public static function get($index) {
		if(!key_exists($index, self::$_language)) {
			throw new P3Base_Language_Exception('translation was not found for "'.$index.'"');
		}

		return self::$_language[$index];
	}
}


?>
